home *** CD-ROM | disk | FTP | other *** search
- Path: prairienet.org!wemccaug
- From: wemccaug@prairienet.org (Wendy E. McCaughrin)
- Newsgroups: comp.lang.c++
- Subject: Re: [Q]Assigning function pointer in C/C++.
- Date: 26 Jan 1996 08:14:34 GMT
- Organization: University of Illinois at Urbana
- Message-ID: <4ea2ha$ap2@vixen.cso.uiuc.edu>
- References: <4doc42$gsb@bmdhh222.bnr.ca> <DL3JJu.5nB.0.queen@torfree.net>
- Reply-To: wemccaug@prairienet.org (Wendy E. McCaughrin)
- NNTP-Posting-Host: firefly.prairienet.org
-
-
- In a previous article, ray.fallon@nt.com (Ray Fallon) says:
-
- >bh332@freenet.toronto.on.ca (Karim Ladha) wrote:
- >>
- >>
- >>How is it possible to assign a declared variable in C++ a pointer to
- >>some function member? If you know of a solution, post. Greatly appreciated.
- >>
- >
- >I response to your question, assigment of pointers to member functions is
- >not possible for the following reason :
- >
- >In 'C' you can only have one instance of a function at any one time. In
- >C++ you can have multiple instances of a class (i.e. objects) and the
- >pointer to the function would not be able to know which object you are
- >referring to. In any case, it is possible to use other methods, and
- >theoritically they are more sound methods. Use the principle of
- >polymorphism.
- This is correct, but there is a simpler answer as well. Member functions
- get invoked through their objects, and upon invocation the object's 'this'
- ptr gets passed to the member function so it can access the object's data
- members. With a ptr to a member function, you could then invoke it without
- going through any object, leaving the 'this' ptr expected by this function
- essentially undefined. (well, maybe it's not a simplet answer, after all.)
-
- -- Scott McC.
-
-